export default {
    namespaced: true,
    state: () => ({
        username: "wang",
        userInfo: {},
        token: ""
    }),
    mutations: {
        setCount(state, data) {
            state.count = state.count + data
        },
        setUserInfo(state, data) {
            state.userInfo = data
        },
        setToken(state, token) {
            state.token = token;
            window.localStorage.setItem("token", token)
        },
        removeToken(state) {
            state.token = "";
            window.localStorage.removeItem("token")
        }
    },
    actions: {
        setUserInfo({ commit }, data) {
            commit("setUserInfo", data)
        },
        setToken({ commit }, token) {
            commit("setToken", token)
        },
        removeToken({ commit }) {
            commit("removeToken")
        }
    },
    getters: {
        getToken(state) {
            return state.token ? state.token : window.localStorage.getItem("token") || ""
        }
    }
}